const paramStr = location.search
// console.log(paramStr)
const params=new URLSearchParams(paramStr)
params.forEach(async (value,key)=>{
	// console.log(value,key)
	const res=await axios({
		url:`cdArticle/getArticleDetailById/${value}`
	})
	// console.log(res.data.result)
	const date=res.data.result
	//获取tag
	const tags=date.tags
	// console.log(tags)
	
	//设置meta和title
	document.querySelector('title').innerHTML=date.title + '_' + date.brands[0].bname + '_' + date.homeCategory + '- 柴垛'
	document.querySelector('[name=keywords]').content=tags + ',' +date.brands[0].bname+ ',' +date.homeCategory+ ",柴垛"
	document.querySelector("[property='og:title']").content=date.title
	document.querySelector("[property='og:description']").content=date.descript
	document.querySelector("[property='og:image']").content=date.coverImg
	document.querySelector("[property='og:url']").content=`https://www.chaiduo.com/article/`+date.id
	document.querySelector("[property='og:release_date']").content=date.createTime
	document.querySelector('[itemprop=dateUpdate]').content=date.createTime
	document.querySelector('[itemprop=datePublished]').content=date.createTime
	document.querySelector('[name=mediaid]').content=date.brands[0].bname
	document.querySelector('[itemprop=image]').content=date.coverImg
	document.querySelector('[rel=canonical]').href=`https://www.chaiduo.com/article/`+date.id
	
	const str=`
	<div class="label">
		<a href="./resBrand.html?id=${date.brands[0].bid}"><span>${date.brands[0].bname}</span></a>
		<span class="byName">${date.homeCategory}</span>
	</div>
	<h3>${date.title}</h3>
	<div class="line"></div>
	${date.content}
	<div class="articleData">
		<span>发布于：${date.createTime}</span>&nbsp;&nbsp;&nbsp;
		<span>浏览量&nbsp;&nbsp;&nbsp;${date.readNum}阅读</span>
	</div>
	<div class="label">
		<a href="./resBrand.html?id=${date.brands[0].bid}">
		${tags.map(item=>{
			return `<span>${item.tname}</span>`
		}).join('')}
		</a>
	</div>`
	document.querySelector('.left').innerHTML=str
	document.querySelector('.byName').addEventListener('click',e=>{
		// console.log(e.target)
		const name=e.target.innerHTML
		// console.log(name)
		location.href=`./resCategory.html?name=${name}`
	})

	
// 获取相关推荐
	const result=await axios({
		url:'cdArticle/getActicleListByBrand',
		method:'POST',
		data:{
			brandId: date.brands[0].bid,
			pageNo: 1,
			pageSize: 4
		}
	})
	// console.log(res.data.result.list)
	const list=result.data.result.list
	document.querySelector('.relate').innerHTML=list.map(item=>{
		return `
		<a href="article.html?aId=${item.id}">
			<li class="recommend">
				<img src=${item.coverImg} alt="">
				<h4>${item.title}</h4>
				<div class="note">
					<span>${item.brands[0].bname}</span>
					<span>${item.homeCategory}</span>
				</div>
			</li>
		</a>`
	}).join('')
	
})
